<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Logic;

use AuctionBack\Model\UserStatisticsModel;

class UserStatisticsLogic extends BaseLogic
{
    protected $autoCheckFields = false;

    protected $userStatisticsModel;

//    protected $redis;

    public function _initialize()
    {
        $this->userStatisticsModel = new UserStatisticsModel();
    }

    /**
     * 添加用户统计
     *
     * @param array $data
     */
    public function addUserStatistics($data = [])
    {
        if (empty($data) || empty($data['user_id'])) {
            return false;
        }
        $data['update_time'] = NOW_TIME;
        return $this->userStatisticsModel->add($data);
    }

    /**
     * 禁用、减少用户普通提问数
     *
     * @param int $userId
     */
    public function decUserStatisticsCommonQuestionNum($userId = 0)
    {
        if (empty($userId)) {
            return false;
        }
        $condition['user_id'] = $userId;
        return $this->userStatisticsModel->where($condition)->setDec('common_question_num');
    }

    /**
     * 禁用、减少用户付费提问数
     *
     * @param int $userId
     */
    public function decUserStatisticsPayQuestionNum($userId = 0)
    {
        if (empty($userId)) {
            return false;
        }
        $condition['user_id'] = $userId;
        return $this->userStatisticsModel->where($condition)->setDec('pay_question_num');
    }
}